/**
 * @description 数据校验 users
 */

// 手机号规则
const phoneNumberRule = {
  type: 'string',
  pattern: '^1[34578]\\d{9}$', // 手机号正则
  errorMessage: '手机号码格式错误'
}

// 手机号 schema
const phoneNumberSchema = {
  type: 'object',
  required: ['phoneNumber'],
  properties: {
    phoneNumber: phoneNumberRule,
    isRemoteTest: {
      type: 'boolean'
    }
  }
}

// 手机号 + 短信验证码 schema
const phoneNumberVeriCodeSchema = {
  type: 'object',
  required: ['phoneNumber', 'veriCode'],
  properties: {
    phoneNumber: phoneNumberRule,
    veriCode: {
      type: 'string',
      pattern: '^\\d{4}$', // 四位数字
      errorMessage: '短信验证码格式错误'
    }
  }
}

// 用户信息 schema
const userInfoSchema = {
  type: 'object',
  // 用户信息要符合 UserModel 配置
  required: ['nickName'],
  properties: {
    nickName: {
      type: 'string',
      errorMessage: '用户昵称类型错误'
    },
    picture: {
      type: 'string',
      errorMessage: '图片地址类型错误'
    }
  }
}

module.exports = {
  phoneNumberSchema,
  phoneNumberVeriCodeSchema,
  userInfoSchema
}
